<?php
define('IN_ECS', true);
require(dirname(__FILE__) . '/includes/init.php');
/* 检查权限 */
admin_priv('kldiy_log_manage');

$act = 'save';



if(isset($_REQUEST['act']) && $_REQUEST['act']=='save'){
	$log_version = $_POST['log_v'];
	$log_details = nl2br($_POST['log_d']);
	$log_date = time();
	$log_title = $log_version.'.u'.$log_date;

	$sql = "insert into kldiy_log (log_title,log_details,log_date,log_version)values('".$log_title."','".$log_details."','".$log_date."','".$log_version."')";
	//var_dump($sql);
	$re = $GLOBALS['db']->query($sql);
	if($re){
		echo "<script>alert('保存完成');</script>";
	}
}

if(isset($_REQUEST['act']) && $_REQUEST['act']=='update'){
	$act = 'update';
	
	if(isset($_POST)&& count($_POST)>0){
		$log_version = $_POST['log_v'];
		$log_details = nl2br($_POST['log_d']);
		$log_id = $_POST['lid'];

		$sql = "update kldiy_log set log_details='".$log_details."', log_version='.$log_version.' where id=".$log_id;
		//var_dump($sql);
		$re = $GLOBALS['db']->query($sql);
		if($re){
			echo "<script>alert('修改完成');</script>";
		}
	}else{
		$sql = "select * from kldiy_log where id=".$_GET['lid'];
		$res = $db->GetRow($sql);
		$smarty->assign('d1', $res);
		
	}
}

$sql = "select * from kldiy_log";
$res = $db->GetAll($sql);

$da = array();
$i = 0;
foreach($res as $d){
	//var_dump($d);
	$da[$i]['id'] = $d['id'];
	$da[$i]['log_title'] = $d['log_title'];
	$da[$i]['log_details'] = $d['log_details'];
	$da[$i]['log_version'] = $d['log_version'];
	$da[$i]['log_date'] = date('Y年m月d日', $d['log_date']);
	$i++;
}
//var_dump($da);

//$log_date = date('Y年m月d日', $res['log_date']);
$smarty->assign('data', $da);
$smarty->assign('act', $act);
//$smarty->assign('log_date', $log_date);


assign_query_info();
$smarty->display('kldiy_log_manage.html');
?>